<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCategoriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->id()->comment('分类表');
            $table->unsignedBigInteger('admin_id')->unsigned()->default(0)->index('admin_id')->comment('创建人:后台管理员id');
            $table->unsignedBigInteger('top_id')->unsigned()->default(0)->comment('顶级分类id');
            $table->unsignedBigInteger('pid')->unsigned()->default(0)->comment('父级分类ID');
            $table->unsignedBigInteger('category_group_id')->comment('群组id');
            $table->integer('level')->default(1)->comment('等级');
            $table->string('path', 100)->nullable()->default('')->comment('从最顶级分类到本级的关系路径，例如：1,2,3,4');
            $table->string('name', 32)->default('')->comment('分类名称');
            $table->string('nickname', 50)->default('')->comment('分类别名');
            $table->string('type')->nullable()->comment('配置类型 1系统配置 0其他配置');
            $table->string('image', 100)->nullable()->default('')->comment('图片或者ICON');
            $table->string('big_image', 100)->nullable()->default('')->comment('大图片');
            $table->string('keywords')->default('')->comment('关键字');
            $table->string('description')->default('')->comment('描述');
            $table->integer('weigh')->default(0)->comment('权重');
            $table->unsignedTinyInteger('status')->default(1)->comment('状态 0 禁用 1 启用');
            $table->json('value')->nullable()->comment('JSON,自定义扩展');
            $table->integer('sort')->default(0)->comment('排序');
            $table->timestamps();
            $table->softDeletes();
            $table->index(['category_group_id', 'top_id', 'pid', 'level'], 'search');
            $table->index('path');
            $table->index('name');
            $table->index(['category_group_id', 'status', 'level']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('categories');
    }
}
